#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#define MAX 40

using namespace std;

char numbers[MAX];

void print(int result) {
   cout << result << endl;
}

void solve() {
   int sum = 0;
   int exponent = strlen(numbers);
   for(int i=0; i<strlen(numbers); i++) 
      sum += ((int)numbers[i]-'0')*((int)pow((double)2, (double)exponent--)-1); 
   print(sum);    
}

void read() {
   char tmp;
   int i = 0;
   bool flag = true;
   
   while(scanf("%c", &tmp) == 1) {
      if(flag) {
         flag = false; 
         if(tmp == '0')  
            break;
      }
      if(tmp == '\n') { 
         flag = true;
         i = 0;
         solve();
         memset(numbers, '\0', sizeof(numbers));
         continue;
      }
      numbers[i++] = tmp;
   }
}

int main() {
   read();
   return 0;
}
